package Test1.GeneralFunction;

import Test1.HCNetSDK;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;

/**
 * Created by panting6 on 2021/3/26.
 */
public class GetFileByTime {
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public void getFileByTime(int lUserID, String sSavedFileName,int iChannelNum,int rY,int rM,int rD,int rH,int rMin,int rS,
                              int pY,int pM,int pD,int pH,int pMin,int pS)
    {
        HCNetSDK.NET_DVR_PLAYCOND m_playcond =new HCNetSDK.NET_DVR_PLAYCOND();
        m_playcond.dwChannel = iChannelNum;
        m_playcond.struStartTime.dwYear = rY;
        m_playcond.struStartTime.dwMonth = rM;
        m_playcond.struStartTime.dwDay = rD;
        m_playcond.struStartTime.dwHour = rH;
        m_playcond.struStartTime.dwMinute = rMin;
        m_playcond.struStartTime.dwSecond = rS;
        m_playcond.struStopTime.dwYear = pY;
        m_playcond.struStopTime.dwMonth = pM;
        m_playcond.struStopTime.dwDay = pD;
        m_playcond.struStopTime.dwHour = pH;
        m_playcond.struStopTime.dwMinute = pMin;
        m_playcond.struStopTime.dwSecond = pS;
        m_playcond.write();

        int bet = 0;
        bet = hCNetSDK.NET_DVR_GetFileByTime_V40(lUserID,sSavedFileName,m_playcond);
        if(bet<0)
        {
            System.out.println( "按时间下载录像文件失败，错误号：" + hCNetSDK.NET_DVR_GetLastError());
        }
        else
        {
            System.out.println( "按时间下载录像文件成功");
        }

        IntByReference pPlayStartInbuffer = new IntByReference(0);
        Pointer pPSInbufferPointer = pPlayStartInbuffer.getPointer();
        Pointer pPSOutbufferPointer = null;
        IntByReference lpOutLen = new IntByReference(0);

        if(!hCNetSDK.NET_DVR_PlayBackControl_V40(bet,1,pPSInbufferPointer,0,pPSOutbufferPointer,lpOutLen))
        {
            System.out.println( "按时间开始下载失败，错误号：" + hCNetSDK.NET_DVR_GetLastError());
        }
        else
        {
            System.out.println( "按时间开始下载成功,保存至："+ sSavedFileName);
        }
    }
}
